﻿using System;
using System.Collections.Generic;
using System.Linq;
using ExpenseSystem.Common;
using ExpenseSystem.Fether;
using ExpenseSystem.Model;
using ExpenseSystem.Lor;


namespace ExpenseSystem.Fether
{
    public class RoleModuleFetcher:SystemFetcher<RoleModuleModel>,IDetailSystemFetcher<RoleModuleModel>
    {
        public IList<RoleModuleModel> ListByModuleId( long moduleId, out string message,out int rows)
        {
            IList<RoleModuleModel> result = List( OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("ModuleId", moduleId).And(Restrain.Eq("Avaliable", true)));
            return result;
        }
        public IList<RoleModuleModel> ListByRoleId(long roleId, out string message,out int rows)
        {
            IList<RoleModuleModel> result = List(OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("RoleId", roleId).And(Restrain.Eq("Avaliable", true)));
            return result;
        }
        public RoleModuleModel GetByRoleIdAndModuleId(long roleId, long moduleId,string action,out string message)
        {
            int rows;
            IList<RoleModuleModel> result = List( OrderBy.GetDefault(), Limit.GetDefault(), out message, out rows, Restrain.Eq("Action", action).And(Restrain.Eq("ModuleId", moduleId)).And(Restrain.Eq("RoleId", roleId)).And(Restrain.Eq("Avaliable", true)));
            if (result.Count > 0)
                return result.First();
            return null;
        }

        public IList<RoleModuleModel> ListByMainId( long mainId, out string message,out int rows)
        {
            return ListByRoleId(mainId,out message,out rows);
        }
    }
}
